from django.http import HttpResponse
from django.shortcuts import render

from operate.models import MyBookshelf
from .models import Category, Book, RecommendIndex, LatestIndex, CategoryPageRecommend, CategoryPageList
from .models import RecommendIndexChapter


# Create your views here.

def index(request):
    cs = Category.objects.all()
    bk = Book.objects.all()
    ri = RecommendIndex.objects.all()
    li = LatestIndex.objects.all()
    return render(request, 'main/index.html', context={"cs": cs, "bk": bk, "ri": ri, "li": li})


def category(request, num):
    cs = Category.objects.all()
    cs2 = Category.objects.filter(id=num)
    cr = CategoryPageRecommend.objects.filter(category=num)
    cl = CategoryPageList.objects.filter(category=num)
    return render(request, 'main/category.html', context={"cs": cs, "cs2": cs2, "cr": cr, "cl": cl})


def ranking(request):
    cs = Category.objects.all()
    return render(request, 'main/ranking.html', context={"cs": cs})


def detail(request, num):
    cs = Category.objects.all()
    bk = Book.objects.filter(id=num)
    bk2 = Book.objects.get(id=num)
    cl = CategoryPageList.objects.filter(id=num)
    return render(request, 'main/detail.html', context={"cs": cs, "bk": bk, "bk2": bk2, "cl": cl})


def detail_category(request, num):
    cs = Category.objects.all()
    cl = CategoryPageList.objects.filter(id=num)
    cl2 = CategoryPageList.objects.get(id=num)
    return render(request, 'main/detail_category.html', context={"cs": cs, "cl": cl, "cl2": cl2})

def detail_index_rec(request, num):
    cs = Category.objects.all()
    ric = RecommendIndexChapter.objects.filter(id=num)
    ric2 = RecommendIndexChapter.objects.all()
    return render(request, 'main/index_rec_detail.html', context={"cs": cs, "ric": ric, "ric2": ric2})
